import axios from 'axios'
import { Toast } from 'vant'
import { getToken } from './localstorage'
const request = axios.create({
  baseURL: 'http://liufusong.top:8080'
})
request.interceptors.request.use((config) => {
  config.headers.authorization = getToken()
  return config
}, (error) => {
  Toast.fail(error.message)
  return Promise.reject(error)
})
request.interceptors.response.use((response) => {
  if (response.data.status >= 400) {
    Toast.success(response.data.description)
  }
  return response
}, (error) => {
  Toast.fail(error.message)
  return Promise.reject(error)
})
export default request
